$(document).ready(function(){
    
   function loadComments(id){
      
      $.post('comment/comment.actions.php', {
           "action":"loadCommentsForChallenge",
           "challenge_id":id
       }, function(data){
           
           //console.log(data);
           var commentView=$('#displayComment');
           commentView.html("");
           $.each(data, function(index, value) {
              
			  commentView.append("<div class='comment_container'><table><tr><td class='dash'><div class='top'></div><div class='bottom'></div></td><td><div class='cc'><p class='comment'>"+value.comment+"</p><p class='sub'><span class='details'>"+value.username+"</span><span class='spacer'>&bull;</span>"+value.date_time+"</p></div></td></tr></table></div>");
              
             // value.comment;
              
           });
           
           
       },"json");
       
   }
    
   loadComments(challenge_id_var);
   
   
   $('#newCommentForm').submit(function(){
       
       //console.log($('#newCommentForm').serialize());
       
       $.post('comment/comment.actions.php', $('#newCommentForm').serialize()+"&action=newComment", function(data){
           console.log(data);
           loadComments(challenge_id_var);
           $('input[name="newComment"]').val("");
       });

return false;

   });
   
   //$('#hover').hover(function(){$('#popup').show();}, function(){$('#popup').hide();});
   
   
});